package cn.wzy.controller;


import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Employee;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.EmployeeService;
import cn.wzy.vo.EmpRoleVo;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * (Employee)表控制层
 *
 * @author makejava
 * @since 2022-12-08 13:53:14
 */
@RestController
@RequestMapping("/employee")
@Api(value = "员工",tags = "员工")
@AnPermission(name = "员工管理",descs = "对员工资源的管理")
public class EmployeeController {
    /**
     * 服务对象
     */
    @Resource
    private EmployeeService employeeService;


    /*
    * 分页查询
    * */
    @PostMapping("/page")
    @AnPermission(name = "员工分页高级查询")
    @ApiOperation(value = "分页查询")
    public ResponseResult employeePage(@RequestBody GoPageVo goPageVo){
        return employeeService.employeePage(goPageVo);
    }

    /*
    * 添加/修改员工
    * */
    @PostMapping
    @AnPermission(name = "员工添加或修改")
    @ApiOperation(value = "添加/修改员工")
    public ResponseResult saveEmp(@RequestBody Employee employee){
        return employeeService.saveEmp(employee);
    }

    /*
    * 删除员工
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "员工id删除")
    @ApiOperation(value = "单个删除员工")
    public ResponseResult delEmp(@PathVariable Long id){
        return employeeService.delEmp(id);
    }


    /*
    * 批量删除
    * */
    @PatchMapping
    @AnPermission(name = "员工批量删除")
    @ApiOperation(value = "批量删除员工")
    public ResponseResult delEmpList(@RequestBody List<Long> ids){
        return employeeService.delEmpList(ids);
    }

    /*
    * 下载头像
    * */
    @PostMapping("/download")
    @AnPermission(name = "员工头像")
    @ApiOperation(value = "下载员工头像")
    public ResponseResult  download(String fileName, HttpServletResponse response){
        return employeeService.download(fileName,response);
    }

    /*
    * 获取所有员工
    * */
    @GetMapping
    @ApiOperation(value = "所有员工")
    @AnPermission(name = "所有员工查询")
    public ResponseResult getAllEmp(){
        return employeeService.getAllEmp();
    }

    /*
    * 给员工设置角色
    * */
    @PostMapping("/roles")
    @ApiOperation(value = "设置员工角色")
    @AnPermission(name="员工角色设置")
    public ResponseResult saveEmpRole(@RequestBody EmpRoleVo empRoleVo){
        return employeeService.saveEmpRole(empRoleVo);
    }

    /*
    * 获取到员工角色sn
    * */
    @GetMapping("/getRoles/{id}")
    @ApiOperation(value = "获取员工角色sn")
    @AnPermission(name = "获取到员工角色sn")
    public ResponseResult getEmpRoleSns(@PathVariable("id") Long id){
        return employeeService.getEmpRoleSns(id);
    }

    /*
    * 通过token 获取到员工信息
    * */
    @GetMapping("/getEmpByToken")
    @ApiOperation(value = "通过token获取到员工信息")
    public ResponseResult getEmpByToken(HttpServletRequest request){
        return  employeeService.getEmpByToken(request);
    }
}

